package com.upload.controller;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;


@Controller
@RequestMapping("/fileUpload")
public class UploadAction {

	@RequestMapping("/upload")
	public String upload(@RequestParam(value = "file", required = false) MultipartFile file,
			HttpServletRequest request, ModelMap model) {
		System.out.println("开始");
		String path = "D:/excel";  //存在D盘
		String fileName = file.getOriginalFilename();
		System.out.println(path);
		File targetFile = new File(path, fileName);
		if (!targetFile.exists()) {
			targetFile.mkdirs();
		}

		// 保存
		try {
			file.transferTo(targetFile);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println( targetFile.getPath());
		model.addAttribute("result", targetFile.getPath());
		return "fileUpload/result";
	}
	
	@RequestMapping("/fileUpload")
	public void fileUpload( ) {
		 System.out.println(111);
	}
}
